package com.ruoyi.web.controller.decision;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.decision.domain.SchemeClassification;
import com.ruoyi.decision.service.ISchemeClassificationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 方案库分类Controller
 * 
 * @author zbw
 * @date 2022-07-20
 */
@RestController
@RequestMapping("/decision/schemeclassification")
public class SchemeClassificationController extends BaseController
{
    @Autowired
    private ISchemeClassificationService schemeClassificationService;


    /**
     * 查询方案库分类列表
     */
    @PreAuthorize("@ss.hasPermi('decision:schemeclassification:list')")
    @GetMapping("/list")
    public TableDataInfo list(SchemeClassification schemeClassification)
    {
        startPage();
        List<SchemeClassification> list = schemeClassificationService.selectSchemeClassificationList(schemeClassification);
        return getDataTable(list);
    }

    /**
     * 导出方案库分类列表
     */
    @PreAuthorize("@ss.hasPermi('decision:schemeclassification:export')")
    @Log(title = "方案库分类", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SchemeClassification schemeClassification)
    {
        List<SchemeClassification> list = schemeClassificationService.selectSchemeClassificationList(schemeClassification);
        ExcelUtil<SchemeClassification> util = new ExcelUtil<SchemeClassification>(SchemeClassification.class);
        util.exportExcel(response, list, "方案库分类数据");
    }

    /**
     * 获取方案库分类详细信息
     */
    @PreAuthorize("@ss.hasPermi('decision:schemeclassification:query')")
    @GetMapping(value = "/{templatetypeid}")
    public AjaxResult getInfo(@PathVariable("templatetypeid") String templatetypeid)
    {
        return AjaxResult.success(schemeClassificationService.selectSchemeClassificationByTemplatetypeid(templatetypeid));
    }

    /**
     * 新增方案库分类
     */
    @PreAuthorize("@ss.hasPermi('decision:schemeclassification:add')")
    @Log(title = "方案库分类", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SchemeClassification schemeClassification)
    {
        return toAjax(schemeClassificationService.insertSchemeClassification(schemeClassification));
    }

    /**
     * 修改方案库分类
     */
    @PreAuthorize("@ss.hasPermi('decision:schemeclassification:edit')")
    @Log(title = "方案库分类", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SchemeClassification schemeClassification)
    {
        return toAjax(schemeClassificationService.updateSchemeClassification(schemeClassification));
    }

    /**
     * 删除方案库分类
     */
    @PreAuthorize("@ss.hasPermi('decision:schemeclassification:remove')")
    @Log(title = "方案库分类", businessType = BusinessType.DELETE)
	@DeleteMapping("/{templatetypeids}")
    public AjaxResult remove(@PathVariable String[] templatetypeids)
    {
        return toAjax(schemeClassificationService.deleteSchemeClassificationByTemplatetypeids(templatetypeids));
    }
}
